<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAttachmentsTable extends Migration
{
    /**
     * 附件表
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 附件表
        Schema::create('attachments', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('ID');
            $table->string('model_id')->nullable()->comment('模型ID');
            $table->string('model_type')->nullable()->comment('模型类型');
            $table->string('name', 200)->default('')->comment('名称');
            $table->string('file_name', 200)->default('')->comment('文件名称');
            $table->string('path')->default('')->comment('路径');
            $table->enum('mime_type', ['video', 'audio', 'pdf', 'document', 'ppt', 'image', 'other'])->default('image')->comment('类型[video:视频,audio:音频,pdf:PDF,document:文档,ppt:PPT, image :图片,other:其他]');
            $table->string('ext', 50)->default('')->comment('后缀');
            $table->integer('size')->nullable()->comment('大小');
            $table->text('content')->nullable()->comment('扩展信息');
            $table->timestamp('created_at')->nullable()->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('修改时间');
            $table->bigInteger('created_admin_id')->default(0)->comment('创建人');
            $table->bigInteger('updated_admin_id')->default(0)->comment('修改人');
        });

        DB::statement('alter table'. ' ' . config('database.connections.mysql.prefix', '') . 'attachments comment "附件表"');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('attachments');        // 附件表
    }
}
